//
//  ZRTabBar.m
//  SinaByOC
//
//  Created by 张锐 on 16/3/15.
//  Copyright © 2016年 zhangr. All rights reserved.
//

#import "ZRTabBar.h"

@implementation ZRTabBar

/**
 *  重写layoutSubviews实现中间按钮
 */
-(void)layoutSubviews{

    [super layoutSubviews];
    
    NSInteger i = 0;
    
    CGFloat barButtonW = [UIScreen mainScreen].bounds.size.width / 5;
    
    CGFloat barButtonH = self.bounds.size.height;
    
    for (UIView * view in self.subviews) {
        
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            if (i == 2) {
                
                UIButton * composeButton = [[UIButton alloc]init];
                
                composeButton.frame = CGRectMake(i * barButtonW, 0, barButtonW, barButtonH);
                
                [composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
                
                [composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
                
                [composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
                
                [composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
                
                [composeButton addTarget:self action:@selector(composeButtonClick) forControlEvents:UIControlEventTouchUpInside];
                
                [self addSubview:composeButton];
                
                i++;
                
            }
            
            view.frame = CGRectMake(i * barButtonW, 0, barButtonW, barButtonH);
            i++;
        }
    }
    
}
/**
 *  composeButton点击
 */
-(void)composeButtonClick{
    
    if (self.composeDelegate) {
        
        [self.composeDelegate tabBarComposeButtonClickDelegate];
        
    }

}

@end
